package com.ztom.beans.factory.support.pojo

import kotlin.reflect.KClass

/**
 * bean 元信息
 *
 * @author ZhangTao
 */
class BeanDefinition(
    var beanClazz: KClass<out Any>,
    var propertyValues: PropertyValues = PropertyValues(),
    var initMethodName: String? = null,
    var destroyMethodName: String? = null,
) {

    companion object {
        const val SCOPE_SINGLETON = "singleton"
        const val SCOPE_PROTOTYPE = "prototype"
    }

    private var singleton: Boolean = true
    private var prototype: Boolean = false

    var scope: String = SCOPE_SINGLETON
        set(value) {
            field = value
            this.singleton = field == SCOPE_SINGLETON
            this.prototype = field == SCOPE_PROTOTYPE
        }

    fun isSingleton(): Boolean {
        return this.singleton
    }

    fun isPrototype(): Boolean {
        return this.prototype
    }

    override fun toString(): String {
        return "BeanDefinition(beanClazz=$beanClazz, propertyValues=$propertyValues, initMethodName=$initMethodName, destroyMethodName=$destroyMethodName, singleton=$singleton, prototype=$prototype, scope='$scope')"
    }
}
